# Maintainer: Wu Zhenyu <wuzy01@qq.com>
_realname=fd

pkgbase=mingw-w64-$_realname
pkgname=$MINGW_PACKAGE_PREFIX-$_realname
pkgver=8.7.0
pkgrel=1
pkgdesc='Simple, fast and user-friendly alternative to find (mingw-w64)'
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url=https://github.com/sharkdp/fd
makedepends=("$MINGW_PACKAGE_PREFIX-rust")
license=(MIT APACHE)
source=("$url/archive/v$pkgver.tar.gz")
sha512sums=('911b9b718f584bed7e569e11f098ede5effdb74822debca677b555e02032844ee7dd5644a5d7ad2d138d358025e08c02590a2ae2e99e8bac4ab1c88835e84c50')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked
}

build() {
  cd "${_realname}-${pkgver}"

  WINAPI_NO_BUNDLED_LIBRARIES=1 \
  cargo build --release --frozen
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}-${pkgver}"

  install -Dm755 target/release/fd "$pkgdir"$MINGW_PREFIX/bin/fd

  make completions
  install -Dm644 autocomplete/fd.bash "$pkgdir"${MINGW_PREFIX}/share/bash-completion/completions/fd
  install -Dm644 autocomplete/fd.fish "$pkgdir"${MINGW_PREFIX}/share/fish/vendor_completions.d/fd.fish
  install -Dm644 autocomplete/_fd "$pkgdir"${MINGW_PREFIX}/share/zsh/site-functions/_fd

  install -Dm644 doc/fd.1 "$pkgdir"$MINGW_PREFIX/share/man/man1/fd.1
  install -Dm644 LICENSE-APACHE "$pkgdir"$MINGW_PREFIX/share/licenses/fd/LICENSE-APACHE
  install -Dm644 LICENSE-MIT "$pkgdir"$MINGW_PREFIX/share/licenses/fd/LICENSE-MIT
}
